function savePageButton(a) {
    editFlag = true;
    survey.buttontype = parseInt($("input[name=qleftpagebutton]:checked").val(), 10);
    $("[id^=q_buttontype_]").each(function(b) {
        var c = $(this).attr("id").split("_");
        var d = questionMap[c[2]];
        $("#q_buttontype_" + d.id).html(getRightPageButtonInnerHtml(d))
    })
}
function saveFormat(d) {
    recordQuestionEdit(d);
    var b = questionMap[d];
    b.format = parseInt($("#qlefteditformat").val(), 10);
    if (b.type == 6 && (b.typeid == 1 || b.typeid == 5)) {
        if (b.typeid == 5) {
            $("#q_answers_" + d).html(getSingleOpenAnswerHtml(b))
        } else {
            var c = "";
            c = b.format == 1 ? "small": (b.format == 2 ? "medium": "large");
            $("#q_format_" + b.id).removeClass("small medium large").addClass(c)
        }
    } else {
        if (b.type == 6 && b.typeid == 12) {
            b.predefine = "";
            $("#q_phone_" + b.id).html(getPhoneInnerHtml(b));
            $("#qlefteditdefine").html(getLeftPhoneDefineInnerHtml(b))
        } else {
            if (b.type == 6 && b.typeid == 9) {
                b.predefine = "";
                $("#qlefteditdateDIV").html(getLeftDateDefineInnerHtml(b));
                $("#q_date_" + b.id + "").html(getDateInnerHtml(b))
            } else {
                if ((b.type == 1 || b.type == 2) && b.typeid == 1) {
                    $("#q_answers_" + b.id).html(getQuestionAnswerHtml(b));
                    $("#q_answers_" + b.id).removeClass("twoColumns").removeClass("threeColumns").removeClass("notStacked").removeClass("radio-select-warp");
                    if (b.format >= 9) {
                        var a = "";
                        if (b.format == 9) {
                            a = "twoColumns"
                        } else {
                            if (b.format == 10) {
                                a = "threeColumns"
                            } else {
                                if (b.format == 11) {
                                    a = "notStacked"
                                } else {
                                    if (b.format == 12) {
                                        a = "radio-select-warp"
                                    }
                                }
                            }
                        }
                        $("#q_answers_" + b.id).addClass(a)
                    }
                }
            }
        }
    }
    questionMap[b.id] = b;
    refreshQuestionHeight(b.id);
    if (b.type == 6 && b.typeid == 9) {
        showDate(d)
    }
}
function saveRangeformat(b) {
    recordQuestionEdit(b);
    var a = questionMap[b];
    a.rangeformat = parseInt($("#qlefteditrangeformat").val(), 10);
    if (a.rangeformat == 1) {
        $("#qlefteditrangeminname").html("最少");
        $("#qlefteditrangemaxname").html("最多")
    } else {
        $("#qlefteditrangeminname").html("最小");
        $("#qlefteditrangemaxname").html("最大")
    }
    questionMap[a.id] = a
}
function saveQRangemin(b) {
    recordQuestionEdit(b);
    var a = questionMap[b];
    if (a.rangeformat == 0) {
        a.rangemin = 0;
        a.rangemax = 0
    } else {
        if (!checkNum($.trim($("#qlefteditrangemin").val()))) {
            a.rangemin = 0;
            $("#qlefteditrangemin").val("")
        } else {
            a.rangemin = parseInt($("#qlefteditrangemin").val(), 10)
        }
    }
    questionMap[a.id] = a
}
function saveQRangemax(b) {
    recordQuestionEdit(b);
    var a = questionMap[b];
    if (a.rangeformat == 0) {
        a.rangemin = 0;
        a.rangemax = 0
    } else {
        if (!checkNum($.trim($("#qlefteditrangemax").val()))) {
            a.rangemax = 0;
            $("#qlefteditrangemax").val("")
        } else {
            a.rangemax = parseInt($("#qlefteditrangemax").val(), 10)
        }
    }
    questionMap[a.id] = a
}
function saveQPhonePredefine(b) {
    recordQuestionEdit(b);
    var a = questionMap[b];
    if (a.type == 6 && a.typeid == 12) {
        if (a.format == 4) {
            a.predefine = $("#qlefteditdefine1").val() + PHONE_SPLIT + $("#qlefteditdefine2").val() + PHONE_SPLIT + $("#qlefteditdefine3").val()
        } else {
            a.predefine = $("#qlefteditdefine1").val()
        }
        $("#q_phone_" + a.id).html(getPhoneInnerHtml(a))
    }
    questionMap[a.id] = a
}
function saveQNormalPredefine(b) {
    recordQuestionEdit(b);
    var a = questionMap[b];
    a.predefine = $("#qlefteditdefinevalue").val();
    $("#q_predefine_" + a.id).val(a.predefine);
    questionMap[a.id] = a
}
function saveColor(h, b) {
    recordQuestionEdit(h);
    var e = questionMap[h];
    if ($("[id^=qlefteditquestioncolor_]:checked").length == 0) {
        $("#qlefteditquestioncolor_" + b).attr("checked", true);
        return
    }
    var f = new Array();
    var g = ColorList.color;
    var a = ColorList.colorName;
    for (var d = 0; d < g.length; d++) {
        if ($("#qlefteditquestioncolor_" + d).attr("checked")) {
            f.push(new Answer({
                name: a[d],
                remark: g[d]
            }))
        }
    }
    e.answers = f;
    $("#q_color_" + e.id).html(getColorInnerHtml(e));
    questionMap[e.id] = e;
    refreshQuestionHeight(e.id)
}
function checkQInstruction(b) {
    recordQuestionEdit(b);
    var a = questionMap[b];
    if ($("#qlefteditinstructioncheck").attr("checked")) {
        intro_UEditor.setEnabled();
        a.instruction = intro_UEditor.getContent()
    } else {
        intro_UEditor.setContent("说明内容");
        intro_UEditor.setDisabled("fullscreen");
        a.instruction = ""
    }
    $("#q_instruction_" + a.id).html(replaceQuestion(a.instruction));
    questionMap[b] = a;
    refreshQuestionHeight(a.id)
}
function saveQInstruction(b) {
    if (!$("#qlefteditinstructioncheck").attr("checked")) {
        return
    }
    recordQuestionEdit(b);
    var a = questionMap[b];
    a.instruction = intro_UEditor.getContent();
    $("#q_instruction_" + a.id).html(replaceQuestion(a.instruction));
    questionMap[b] = a;
    refreshQuestionHeight(b)
}
function showDate(b) {
    var a = questionMap[b];
    if (a.format == 7) {
        showYearMonth(b)
    } else {
        showYearMonthDay(b)
    }
}
function showYearMonthDay(a) {
    $("#qlefteditdate_year, #qlefteditdate_month, #qlefteditdate_day").bind("click", 
    function(b) {
        $("#qlefteditdate").focus()
    });
    $("#qlefteditdate").datepicker({
        dateFormat: "yy-mm-dd",
        onSelect: function(d, c) {
            recordQuestionEdit(a);
            var b = questionMap[a];
            $("#qlefteditdate_year").val(d.split(DATE_SPLIT)[0]);
            $("#qlefteditdate_month").val(d.split(DATE_SPLIT)[1]);
            $("#q_year_" + a).val(d.split(DATE_SPLIT)[0]);
            $("#q_month_" + a).val(d.split(DATE_SPLIT)[1]);
            if (b.format == 7) {} else {
                $("#qlefteditdate_day").val(d.split(DATE_SPLIT)[2]);
                $("#q_day_" + a).val(d.split(DATE_SPLIT)[2])
            }
            b.predefine = d;
            questionMap[b.id] = b
        }
    })
}
function showYearMonth(a) {
    $("#qlefteditdate_year, #qlefteditdate_month").bind("click", 
    function(b) {
        $("#qlefteditdateimg").trigger("click")
    });
    $("#qlefteditdateimg").monthpicker({
        yearEl: $("#qlefteditdate_year"),
        monthEl: $("#qlefteditdate_month"),
        defaultYear: (new Date()).getFullYear(),
        defaultMonth: (new Date()).getMonth(),
        callbackFn: function(b, d) {
            recordQuestionEdit(a);
            var c = questionMap[a];
            $("#q_year_" + a).val(b);
            $("#q_month_" + a).val(d);
            c.predefine = b + DATE_SPLIT + d;
            questionMap[c.id] = c
        }
    })
}
function showTime(a) {
    $("#qlefteditdate_hour, #qlefteditdate_minute, #qlefteditdate_second").bind("click", 
    function(b) {
        $("#qleftedittime").focus()
    });
    $("#qleftedittime").timepicker({
        showSecond: true,
        timeFormat: "hh:mm:ss",
        onSelect: function(c, b) {
            setTimeout(function() {
                saveTime(a, c)
            },
            100)
        },
        onClose: function(c, b) {
            setTimeout(function() {
                saveTime(a, c)
            },
            100)
        }
    })
}
function saveTime(c, b) {
    recordQuestionEdit(c);
    var a = questionMap[c];
    $("#qlefteditdate_hour").val(b.split(TIME_SPLIT)[0]);
    $("#qlefteditdate_minute").val(b.split(TIME_SPLIT)[1]);
    $("#qlefteditdate_second").val(b.split(TIME_SPLIT)[2]);
    $("#q_hour_" + c).val(b.split(TIME_SPLIT)[0]);
    $("#q_minute_" + c).val(b.split(TIME_SPLIT)[1]);
    $("#q_second_" + c).val(b.split(TIME_SPLIT)[2]);
    a.predefine = b;
    questionMap[a.id] = a
};